﻿// JScript 文件
document.oncontextmenu=function(e){return false;}

var strsql = null;
var major = 0;
var minor = 0;
var id0 = null;

var vList = null;

var Menu = new CtnMenuCtrl("Menu")

function Init()
{
    major = 95;
    minor = 870;
    vList = new CtnListCtrl("vList");
    vList.create("result");
    vList.bfill = 1;
    vList.pagesize = 10;
    vList.onRowClick  = onRowClick;
    vList.onRowRClick  = onRowClick;
    vList.onGoPage = gotoPage;
    vList.goPage(1);
    
    $("result").oncontextmenu  = function (evt)
    
    { 
        Menu.clear();
        with(Menu)
            {            
                addEvent("查看","View()");
                addEvent("编辑", "Edit()");
                addEvent("添加","Add()");
            } 
        Menu.show(evt);
        return false;
    }
}

function gotoPage(page)
{
    var vUrl = "_method=GetDwList&major="+escape(major)+"&minor="+escape(minor)+"&strsql="+escape(strsql)+"&pageno="+page+"&size="+vList.pagesize
    var vData = CtnTrans.getText("/main.ashx", "post", vUrl);
    if (!CtnError.validate(vData))
    {
        CtnError.show();
        return;
    }
    else if(vData == "false")
    {
        CtnDlg.msg("没有符合条件的记录!") 
    }
    else
    {
        vList.reset();
        vList.insertXml(vData, 1);
        vList.show();
    }
}

function View()
{
    if(id0 == null)
    {
        CtnDlg.warning("请选择记录");
        return ;
    }
    top.ExecuteATool(top.m_vt.FUN_ATT, [major, minor, id0.text, 'view', null])
}

function Edit()
{
    if(id0 == null)
    {
        CtnDlg.warning("请选择记录");
        return ;
    }
    top.ExecuteATool(top.m_vt.FUN_ATT, [major, minor, id0.text, 'edit', AttEdit])
}

function Add()
{
    if(id0 == null)
    {
        CtnDlg.warning("请选择记录");
        return ;
    }
    top.ExecuteATool(top.m_vt.FUN_ATT, [major, minor, id0.text, 'add', AttAdd])
}

function AddEnt()
{ 
}

function onRowClick(evt, rowno)
{
    var rowobj = vList.getRow(rowno);
    id0 = rowobj.getCell("id0");
}

function AttEdit(dlg)
{
    var vGrid = dlg.wnd.getXml()
    var xmlDoc = CtnTrans.getText("/main.ashx?_method=EditGldwInfo", "post", escape(vGrid))
    if (!CtnError.validate(xmlDoc))
    {
        CtnError.show();
    }
    dlg.close()
    vList.goPage(vList.curpage);
}

function AttAdd(dlg)
{
    var vGrid = dlg.wnd.getXml()
    var xmlDoc = CtnTrans.getText("/main.ashx?_method=AddGldwInfo", "post", escape(vGrid))
    if (!CtnError.validate(xmlDoc))
    {
        CtnError.show();
    }
    dlg.close()
    vList.goPage(1);
}


///公司组织管理界面获取区域信息
//默认取type=="1"按备注获得区域信息;  type=="2"为按名称获取区域信息
function InitDwZqy()
{
    var vXmlDoc = CtnTrans.getXml("/main.ashx?", "post", "_method=GetDwQy");
    if (!CtnError.validate(vXmlDoc))
    {
        CtnError.show();
        return;
    }
    else if ($XML(vXmlDoc.lastChild, "type") == "1")
    {
        DwZqyMod1(vXmlDoc);
    }
    else
    {
        DwZqyMod2(vXmlDoc);
    }
}

function GetDwMc()
{
    var vXmlDoc = CtnTrans.getXml("/main.ashx?", "post", "_method=GetDwQy");
    if (!CtnError.validate(vXmlDoc))
    {
        CtnError.show();
        return;
    }
    else if ($XML(vXmlDoc.lastChild, "type") == "1")
    {
        DwMcMod1(vXmlDoc);
    }
    else
    {
        DwMcMod2(vXmlDoc);
    }
}

function GetBmManage()
{
    var vXmlDoc = CtnTrans.getXml("/main.ashx?", "post", "_method=GetDwQy");
    if (!CtnError.validate(vXmlDoc))
    {
        CtnError.show();
        return;
    }
    else if ($XML(vXmlDoc.lastChild, "type") == "1")
    {
        BmManageMod1(vXmlDoc);
    }
    else
    {
        BmManageMod2(vXmlDoc);
    }
}

function GetDwUse()
{
    var vXmlDoc = CtnTrans.getXml("/main.ashx?", "post", "_method=GetDwQy");
    if (!CtnError.validate(vXmlDoc))
    {
        CtnError.show();
        return;
    }
    else if ($XML(vXmlDoc.lastChild, "type") == "1")
    {
        DwUseMod1(vXmlDoc);
    }
    else
    {
        DwUseMod2(vXmlDoc);
    }
}

//按备注名称初始化区域
function DwZqyMod1(vXmlDoc)
{
    var vQyNodes = vXmlDoc.selectNodes("items/att")

    var vRoot = document.createElement("option")
    vRoot.value = "";
    vRoot.text  = "";
    $("Fcomp").options.add(vRoot)

    for (var i = 0; i < vQyNodes.length; ++i)
    {
        var strId = $XML(vQyNodes[i].selectSingleNode("id0"))
        var strVal = $XML(vQyNodes[i].selectSingleNode("bz"))//取备注信息
        var parts = strVal.split('.')
        strVal = parts[0]
        
        var n = 0
        for(var j = 0; j < i; ++j)
        {
          var strSame = $XML(vQyNodes[j].selectSingleNode("bz")).split('.')[0];
          if (strVal == strSame)
          {
            n++;
            continue
          }
        }
        if(n == 0)
        {
          var vTmp = document.createElement("option")
          vTmp.value = strId;
          vTmp.text  = strVal;
          vTmp.title = strVal;
          $("Fcomp").options.add(vTmp);
        }
    }
}

function DwMcMod1(vXmlDoc)
{
   if ($("Fcomp").selectedIndex > 0)
   {
        var vQyNodes = vXmlDoc.selectNodes("items/att")

        $("ManageDept").innerHTML = ""
        var vRoot = document.createElement("option")
        vRoot.value = "";
        vRoot.text  = "";
        $("ManageDept").options.add(vRoot)

        $("UseDept").innerHTML = ""
        var vRoot = document.createElement("option")
        vRoot.value = "";
        vRoot.text  = "";
        $("UseDept").options.add(vRoot)

        for (var i = 0; i < vQyNodes.length; ++i)
        {
            var strId = $XML(vQyNodes[i].selectSingleNode("id0"))
            var strVal = $XML(vQyNodes[i].selectSingleNode("bz"))//取备注信息
            var parts = strVal.split('.')
            var strLimit = parts[0]
            var index = $("Fcomp").selectedIndex;
            
            if(strLimit == $("Fcomp")[index].text && parts[1] != null)
            {
               var n = 0
               var strDept = parts[1]
               for (var j = 0; j < i; ++j)
               {
                   var strSame = $XML(vQyNodes[j].selectSingleNode("bz")).split('.')[1];
                   if(strDept == strSame)
                   {
                     n++
                     continue
                   }
               }
               if (n == 0)
               {
                    var vTmp = document.createElement("option")
                    vTmp.value = strId;
                    vTmp.text  = strDept;
                    vTmp.title = strDept;
                    $("ManageDept").options.add(vTmp)

                    var vUseTmp = document.createElement("option")
                    vUseTmp.value = strId;
                    vUseTmp.text  = strDept;
                    vUseTmp.title = strDept;
                    $("UseDept").options.add(vUseTmp)
               }
            }
            else
            {
              continue
            }
        }
   }
}

function BmManageMod1(vXmlDoc)
{
    if ($("ManageDept").selectedIndex > 0)
    {
        var vQyNodes = vXmlDoc.selectNodes("items/att")

        $("FiliManage").innerHTML = ""
        var vRoot = document.createElement("option")
        vRoot.value = "";
        vRoot.text  = "";
        $("FiliManage").options.add(vRoot)

        for (var i = 0; i < vQyNodes.length; ++i)
        {
            var strId = $XML(vQyNodes[i].selectSingleNode("id0"))
            var strVal = $XML(vQyNodes[i].selectSingleNode("bz"))//取备注信息
            var parts = strVal.split('.')
            var strLimit = parts[0]
            var strZlimit = parts[1]
            var index = $("Fcomp").selectedIndex;
            var dex = $("ManageDept").selectedIndex; 

            if(strLimit == $("Fcomp")[index].text && strZlimit == $("ManageDept")[dex].text && parts[1] != null && parts[2] != null)
            {
               var strZDemp = parts[2]
               var vZtmp = document.createElement("option")
               vZtmp.value = strId;
               vZtmp.text  = strZDemp;
               vZtmp.title = strZDemp;
               $("FiliManage").options.add(vZtmp);
            }
            else
            {
              continue
            }
        }
    }
}

function DwUseMod1(vXmlDoc)
{
    if ($("UseDept").selectedIndex > 0)
    {
        var vQyNodes = vXmlDoc.selectNodes("items/att")

        $("filiUse").innerHTML = "";
        var vRoot = document.createElement("option")
        vRoot.value = "";
        vRoot.text  = "";
        $("filiUse").options.add(vRoot)
        
        for (var i = 0; i < vQyNodes.length; ++i)
        {
            var strId = $XML(vQyNodes[i].selectSingleNode("id0"))
            var strVal = $XML(vQyNodes[i].selectSingleNode("bz"))//取备注信息
            var parts = strVal.split('.')
            var strLimit = parts[0]
            var strZlimit = parts[1]
            var index = $("Fcomp").selectedIndex;
            var dex = $("UseDept").selectedIndex;
            
            if(strLimit == $("Fcomp")[index].text && strZlimit == $("UseDept")[dex].text && parts[1] != null && parts[2] != null)
            {
               var strZDemp = parts[2]
               var vUseZtmp = document.createElement("option")
               vUseZtmp.value = strId;
               vUseZtmp.text  = strZDemp;
               vUseZtmp.title = strZDemp;
               $("filiUse").options.add(vUseZtmp);
            }
            else
            {
              continue
            }
        }
    }
}

//按子区域名称取得各区域值
function DwZqyMod2(vXmlDoc)
{
    var vQyNodes = vXmlDoc.selectNodes("items/att")

    var vRoot = document.createElement("option")
    vRoot.value = "";
    vRoot.text  = "";
    $("Fcomp").options.add(vRoot)

    for (var i = 0; i < vQyNodes.length; ++i)
    {
        var strId = $XML(vQyNodes[i].selectSingleNode("id0"))
        var strVal = $XML(vQyNodes[i].selectSingleNode("zqymc")) //取子区域名称

        var n = 0
        for(var j = 0; j < i; ++j)
        {
          var strSame = $XML(vQyNodes[j].selectSingleNode("zqymc"))
          if (strVal == strSame)
          {
            n++;
            continue
          }
        }
        if(n == 0)
        {
          var vTmp = document.createElement("option")
          vTmp.value = strId;
          vTmp.text  = strVal;
          vTmp.title = strVal;
          $("Fcomp").options.add(vTmp);
        }
    }
}

//取单位名称dwmc
function DwMcMod2(vXmlDoc)
{
    if ($("Fcomp").selectedIndex > 0)
    {
        var vQyNodes = vXmlDoc.selectNodes("items/att")

        $("ManageDept").innerHTML = ""
        var vRoot = document.createElement("option")
        vRoot.value = "";
        vRoot.text  = "";
        $("ManageDept").options.add(vRoot)
        
        $("UseDept").innerHTML = ""
        var vRoot = document.createElement("option")
        vRoot.value = "";
        vRoot.text  = "";
        $("UseDept").options.add(vRoot)

        for (var i = 0; i < vQyNodes.length; ++i)
        {
            var vIdNode = vQyNodes[i].selectSingleNode("id0")
            var vzqyMcNode = vQyNodes[i].selectSingleNode("zqymc")
            var vdwMcNode = vQyNodes[i].selectSingleNode("dwmc")
            var strValzqyMc = $XML(vzqyMcNode)   //取子区域名称
            var strValdwMc = $XML(vdwMcNode)    //取单位名称
            var index = $("Fcomp").selectedIndex;
            
            if(strValzqyMc == $("Fcomp")[index].text && strValdwMc != null)
            {
                var n = 0
                for(var j = 0; j < i; ++j)
                {
                  var strSame = $XML(vQyNodes[j].selectSingleNode("dwmc"))
                  if (strValdwMc == strSame)
                  {
                    n++;
                    continue
                  }
                }
                if(n == 0)
                {
                  var vTmp = document.createElement("option")
                  vTmp.value = $XML(vIdNode);
                  vTmp.text  = strValdwMc;
                  vTmp.title = strValdwMc;
                  $("ManageDept").options.add(vTmp);

                  var vUseTmp = document.createElement("option")
                  vUseTmp.value = $XML(vIdNode);
                  vUseTmp.text  = strValdwMc;
                  vUseTmp.title = strValdwMc;
                  $("UseDept").options.add(vUseTmp)
                }
            }
            else
            {
              continue
            }
        }
    }
}

//取管理部门名称bmmc
function BmManageMod2(vXmlDoc)
{
  if ($("ManageDept").selectedIndex > 0)
  {
     var vQyNodes = vXmlDoc.selectNodes("items/att")
    
     $("FiliManage").innerHTML = ""
     var vRoot = document.createElement("option")
     vRoot.value = "";
     vRoot.text  = "";
     $("FiliManage").options.add(vRoot)

     for (var i = 0; i < vQyNodes.length; ++i)
     {
        var vIdNode = vQyNodes[i].selectSingleNode("id0")
        var vzqyMcNode = vQyNodes[i].selectSingleNode("zqymc")
        var vdwMcNode = vQyNodes[i].selectSingleNode("dwmc")
        var vbmMcNode = vQyNodes[i].selectSingleNode("bmmc")
        var strValzqy = $XML(vzqyMcNode)   //子区域名称
        var strValdw = $XML(vdwMcNode)   //单位名称
        var strValbm = $XML(vbmMcNode)   //部门名称
        var index = $("Fcomp").selectedIndex;
        var dex = $("ManageDept").selectedIndex;
        
        if(strValzqy == $("Fcomp")[index].text && strValdw == $("ManageDept")[dex].text && strValbm != null)
        {
            var n = 0
            for(var j = 0; j < i; ++j)
            {
               var strSame = $XML(vQyNodes[j].selectSingleNode("bmmc"))
               if (strValbm == strSame)
               {
                 n++;
                 continue
               }
            }
            if(n == 0)
            {
               var vTmp = document.createElement("option")
               vTmp.value = $XML(vIdNode);
               vTmp.text  = strValbm;
               vTmp.title = strValbm;
               $("FiliManage").options.add(vTmp);
            }
        }
        else
        {
           continue
        }
     }
  }
}

//取使用部门名称bmmc
function DwUseMod2(vXmlDoc)
{
    if ($("UseDept").selectedIndex > 0)
    {
        var vQyNodes = vXmlDoc.selectNodes("items/att")

        $("filiUse").innerHTML = ""
        var vRoot = document.createElement("option")
        vRoot.value = "";
        vRoot.text  = "";
        $("filiUse").options.add(vRoot)

        for (var i = 0; i < vQyNodes.length; ++i)
        {
            var vIdNode = vQyNodes[i].selectSingleNode("id0")
            var vzqyMcNode = vQyNodes[i].selectSingleNode("zqymc")
            var vdwMcNode = vQyNodes[i].selectSingleNode("dwmc")
            var vbmMcNode = vQyNodes[i].selectSingleNode("bmmc")
            var strValzqy = $XML(vzqyMcNode)   //子区域名称
            var strValdw = $XML(vdwMcNode)    //单位名称
            var strValbm = $XML(vbmMcNode)    //部门名称
            var index = $("Fcomp").selectedIndex;
            var dex = $("UseDept").selectedIndex;
            
            if(strValzqy == $("Fcomp")[index].text && strValdw == $("UseDept")[dex].text && strValbm != null)
            {
                var n = 0
                for(var j = 0; j < i; ++j)
                {
                   var strSame = $XML(vQyNodes[j].selectSingleNode("bmmc"))
                   if (strValbm == strSame)
                   {
                     n++;
                     continue
                   }
                }
                if(n == 0)
                {
                   var vTmp = document.createElement("option")
                   vTmp.value = $XML(vIdNode);
                   vTmp.text  = strValbm;
                   vTmp.title = strValbm;
                   $("filiUse").options.add(vTmp);
                }
            }
            else
            {
               continue
            }
        }
    }
}
